package com.pac.analysis.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.common.tools.TimeTools;
import com.pac.analysis.bean.AbortionMonthF2Bean;
import com.pac.analysis.bean.OptionProportionBean;
import com.pac.analysis.bean.UserMonthBean;
import com.pac.analysis.dao.UserAnalysisDao;
import com.pac.analysis.service.UserAnalysisService;

/**
 * 患者分析
 * 
 * @author lujun.chen
 * @version [版本号, 2015年12月30日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Service(value = "userAnalysisService")
public class UserAnalysisServiceImpl implements UserAnalysisService {

	@Autowired
	private UserAnalysisDao userAnalysisDao;

	@Override
	public List<UserMonthBean> countUserMonth(UserMonthBean userMonthBean) {
		return userAnalysisDao.countUserMonth(userMonthBean);
	}

	@Override
	public List<AbortionMonthF2Bean> countAbortionMonthF2(
			AbortionMonthF2Bean abortionMonthF2Bean) {
		if (StringUtils.isEmpty(abortionMonthF2Bean.getDateStart())) {
			String dateStart = TimeTools.now("yyyy") + "-01-01";
			abortionMonthF2Bean.setDateStart(dateStart);
		}
		if (StringUtils.isEmpty(abortionMonthF2Bean.getDateEnd())) {
			String dateEnd = TimeTools.now("yyyy-MM-dd");
			abortionMonthF2Bean.setDateEnd(dateEnd);
		}
		return userAnalysisDao.countAbortionMonthF2(abortionMonthF2Bean);
	}

	@Override
	public List<OptionProportionBean> countAbortionReasonF2(
			OptionProportionBean optionProportionBean) {
		if (StringUtils.isEmpty(optionProportionBean.getDateStart())) {
			String dateStart = TimeTools.now("yyyy") + "-01-01";
			optionProportionBean.setDateStart(dateStart);
		}
		if (StringUtils.isEmpty(optionProportionBean.getDateEnd())) {
			String dateEnd = TimeTools.now("yyyy-MM-dd");
			optionProportionBean.setDateEnd(dateEnd);
		}
		return userAnalysisDao.countAbortionReasonF2(optionProportionBean);
	}

	@Override
	public List<AbortionMonthF2Bean> countMonthFollow(
			OptionProportionBean optionProportionBean) {
		if (StringUtils.isEmpty(optionProportionBean.getDateStart())) {
			String dateStart = TimeTools.now("yyyy") + "-01-01";
			optionProportionBean.setDateStart(dateStart);
		}
		if (StringUtils.isEmpty(optionProportionBean.getDateEnd())) {
			String dateEnd = TimeTools.now("yyyy-MM-dd");
			optionProportionBean.setDateEnd(dateEnd);
		}

		List<AbortionMonthF2Bean> abortionMonthF2ListR = new ArrayList<AbortionMonthF2Bean>();

		AbortionMonthF2Bean abortionMonthF2Bean = new AbortionMonthF2Bean();
		abortionMonthF2Bean.setDateStart(optionProportionBean.getDateStart());
		abortionMonthF2Bean.setDateEnd(optionProportionBean.getDateEnd());
		abortionMonthF2Bean.setDoctorUserId(optionProportionBean
				.getDoctorUserId());
		List<AbortionMonthF2Bean> abortionMonthF2List = userAnalysisDao
				.countAbortionMonthF2(abortionMonthF2Bean);
		if (null != abortionMonthF2List) {
			for (AbortionMonthF2Bean abortionMonthF2R : abortionMonthF2List) {
				optionProportionBean.setDiagnosisMonth(abortionMonthF2R
						.getAnMonth());
				int num = userAnalysisDao
						.countMonthFollow(optionProportionBean);
				AbortionMonthF2Bean abortionMonthF2 = new AbortionMonthF2Bean();
				abortionMonthF2.setAnMonth(abortionMonthF2R.getAnMonth());
				abortionMonthF2.setNum(num);
				abortionMonthF2ListR.add(abortionMonthF2);
			}
		}

		return abortionMonthF2ListR;
	}

	@Override
	public int abortionTotalNum(AbortionMonthF2Bean abortionMonthF2Bean) {
		return userAnalysisDao.abortionTotalNum(abortionMonthF2Bean);
	}

	@Override
	public int abortionMonthNum(OptionProportionBean optionProportionBean) {
		return userAnalysisDao.abortionMonthNum(optionProportionBean);
	}
	
	

}
